package com.ssm.sfzy.service.impl;

import com.ssm.sfzy.entity.Good;
import com.ssm.sfzy.entity.TeacherGoods;
import com.ssm.sfzy.mapper.GoodMapper;
import com.ssm.sfzy.mapper.TeacherGoodsMapper;
import com.ssm.sfzy.service.TeacherGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @ClassName TeacherGoodsServiceImpl
 * @Author xiaoliu
 * @Date 2024年04月07日 9:11
 */
@Service
public class TeacherGoodsServiceImpl implements TeacherGoodsService {

    @Autowired
    private TeacherGoodsMapper teacherGoodsMapper;
    @Autowired
    private GoodMapper goodMapper;
    @Override
    public void add(TeacherGoods entity) {
        teacherGoodsMapper.insert(entity);
    }

    @Override
    public void edit(TeacherGoods entity) {

    }

    @Override
    public void remove(Integer id) {
        teacherGoodsMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {

    }

    @Override
    public List<TeacherGoods> find(TeacherGoods entity) {
        return null;
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, TeacherGoods entity) {
        return null;
    }

    @Override
    public TeacherGoods findById(Integer id) {
        return null;
    }


    @Override
    public List<TeacherGoods> findAllGoods(Integer id) {
        List<TeacherGoods> teacherGoods = teacherGoodsMapper.findAllGoods(id);

        return teacherGoods;
    }

    @Override
    public List<TeacherGoods> getByTeacherId(Integer teacherId) {
        List<TeacherGoods> teacherGoods = teacherGoodsMapper.getByTeacherId(teacherId);
        for (TeacherGoods teacherGood: teacherGoods){
            Integer goodId = teacherGood.getGoodId();
            Good good = goodMapper.selectById(goodId);
            String name = good.getName();
            teacherGood.setGoodName(name);
        }

        return teacherGoods;
    }
}
